<?php

/**
 * [PHPFOX_HEADER]
 */
defined('PHPFOX') or exit('NO DICE!');

/**
 * 
 * 
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package 		Phpfox_Service
 * @version 		$Id: process.class.php 2738 2011-07-15 10:28:44Z Miguel_Espinoza $
 */
class Connectsocial_Service_Connectsocial extends Phpfox_Service {

    /**
     * Class constructor
     */
    public function __construct() {
        $this->_sTable = Phpfox::getT('social_connect');
    }
    
    /**
     * get Row social connect
     * 
     * @param type $mConds
     * @return type
     */
    public function get($mConds) {
        $aRow = $this->database()->select('*')
                ->from($this->_sTable, 'sc')
                ->where($mConds)
                ->execute('getRow');
        
        return $aRow;
    }
    
    public function getByUser($iUserId = NULL) {
        if($iUserId === NULL) {
            $iUserId = Phpfox::getUserId();
        }
        
        $aRows = $this->database()->select('*')
                ->from($this->_sTable, 'sc')
                ->where('user_id = ' . (int) $iUserId)
                ->execute('getRows');
        
        if($aRows) {
            foreach($aRows as &$item) {
                $aProfile = @unserialize($item['profile_cache']);
                $item['display_name_show'] = $aProfile['displayName'] ? $aProfile['displayName'] : '';
            }
        }
        
        return $aRows;
    }
    /**
     * get list social
     * 
     * @param type $aListSocial
     * @param type $iUserId
     * @return boolean
     */
    public function getListSocial($aListSocial, $iUserId = NULL) {
        if($iUserId === NULL) {
            $iUserId = Phpfox::getUserId();
        }
        
        if(!is_array($aListSocial)) {
            $aListSocial = array($aListSocial);
        }
        
        $sListSocial = implode(',', $aListSocial);
        
        if(!$sListSocial) {
            return FALSE;
        }
        
        $aRows = $this->database()->select('*')
                ->from($this->_sTable, 'sc')
                ->where('sc.user_id = ' . $iUserId . ' AND sc.social_connect_id IN (' . $sListSocial . ')')
                ->execute('getRows');
        
        if($aRows) {
            return $aRows;
        }
        
        return FALSE;
    }
}

?>